//Rectangular Search Directions
//When direction = 'C' 
//When direction = 'E'
//When direction = 'G'
//When direction = 'A'

//Oblique Search Directions
//When direction = 'D' 
//When direction = 'F'
//When direction = 'H'
//When direction = 'B'

BOOL change = FALSE;
int count = 0;
count++; //count = 1

//Conditional statements for perimeter pixel search when direction = 'c'
if(((Is_Pixel(srce_x, srce_y, x += 1, y -= 1) == FALSE) && (Is_Pixel(srce_x, srce_y, x, y -= 1) == TRUE))
{    
    pixelcount++;
    dx = x; dy =  y -= 1
    char dir = GetDirection("x,y-=1"); //Compare strings
    if(dir != direction) change = TRUE;
}
if(((Is_Pixel(srce_x, srce_y, x += 1, y) == FALSE) && (Is_Pixel(srce_x, srce_y, x += 1, y -= 1) == TRUE))
{    
    pixelcount++;
    dx = x; dy =  y -= 1
    char dir = GetDirection("x+=1,y-=1"); //Compare strings
    if(dir != direction) change = TRUE;
}
if(((Is_Pixel(srce_x, srce_y, x += 1, y += 1) == FALSE) && (Is_Pixel(srce_x, srce_y, x += 1, y) == TRUE))
{    
    pixelcount++;
    dx = x; dy =  y -= 1
    char dir = GetDirection("x+=1,y"); //Compare strings
    if(dir != direction) change = TRUE;
}
if(((Is_Pixel(srce_x, srce_y, x, y += 1) == FALSE) && (Is_Pixel(srce_x, srce_y, x += 1, y += 1) == TRUE))
{    
    pixelcount++;
    dx = x; dy =  y -= 1
    char dir = GetDirection("x+=1,y+=1"); //Compare strings
    if(dir != direction) change = TRUE;
}



...
if(change == TRUE) 
{
    //Change of direction
    Printf("Current Direction: %c\n", direction;
    direction = dir;

    //Store pixelcount
    //Don't count the pixel before the direction change //pixelcount - 1
    Printf("Current Pixel Count: %d\n", pixelcount - 1;
    chaincode->Code[count] = pixelcount - 1;
    chaincode->Code[count+1] = dir;
    //But we count the pixel after the direction change //pixelcount = 1
    pixelcount = 1; //Includes    
    count += 2;
}

...
chaincount = count - 1;

//Helper Functions:
BOOL Is_Pixel(struct *IconImage im, int srce_x, int srce_y, int dx, int dy)
{
    BOOL value = FALSE;
    srce_xy = (dy * width + dx) * 4;
    int alpha = im->ImageData[srce_xy];
    if (alpha == 255) value = TRUE;
    return value;
}
unsigned char GetDirection(unsigned char *code)
{
    unsigned char d;
    //Compare string to lookup table to get direction
    if(code == "x+=1,y+=1") d = 'a';
    if(code == "x+=1,y") d = 'c';
    if(code == "x,y-=1") d = 'e';
    return d;
}


//New Functions:
Draw_Large_Image
Draw_Icon_Image
Save_Large_Image
Save_Icon_Image
Write_Pixel
Is_Pixel
GetDirection
Adjust_Brightness
Adjust_Saturation

Save_Icon_Image twice to save a .info file. It saves ARGB.
Don't use Save_Large_Image. It only saves RGB Images!

